﻿#ifndef __SSASTAR_H__
#define __SSASTAR_H__
#include "../container/ssTDArray.h"
#include "../container/ssUniqueArray.h"

//网格原点在左下角
namespace StarSeeker
{

struct ssAStarCell
{
	ulint row;
	ulint colum;
	i32 weight;
	ulint father;

	bool operator == (const ssAStarCell& asc)
	{
		return (row==asc.row && colum == asc.colum);
	}
};

//地图网格原点在左下角，等价于列为X坐标，行为Y坐标
class ssAStar
{
public:
	ssAStar();
	~ssAStar();

	bool Init(ulint row, ulint colum, i8* obstacleLevelArr, ulint arrSize);
	//寻路
	bool PathFinding(ulint beginRow, ulint beginColum, ulint endRow, ulint endColum);
	//获取结果
	void GetResult(ssArray<ulint>& out, bool twoDimensional=false);
private:
	//寻路消耗计算
	i32 GetCellWeight(ulint endRow, ulint endColum, ulint row, ulint colum, bool isOblique);
	//获取周围8个格子
	void GetAroundCell(ulint endRow, ulint endColum, ulint row, ulint colum, ssArray<ssAStarCell, 8>& out);
private:
	ssTDArray<i8>				m_cellArr;		//网格权限
	u8								m_obstacleLevel;//禁止移动的权限等级
	ssUniqueArray<ssAStarCell>	m_openList;
	ssUniqueArray<ssAStarCell>	m_closeList;
	ssArray<ssAStarCell, 8>		m_tempCells;
	ssArray<ulint>				m_result;		//保存结果
};

}
#endif
